public without sharing class PriceHander {
    
        ///新建和更新 删除 价格的时候 将价格对应的公司 汇总到相应的产品上
	///新建
	public static void gatherCom(Set<Id> proset){
		List<Price__c> plist = [select Id ,Product__c,Company__c from Price__c where Product__c in:proset and ClosePrice__c != true  and (MarketPrice__c != null or   InvoiceDealerPrice__c != null or  HospitalManagerPrice__c!=null  or   AreaDealerPrice__c != null )]; 
		Map<String,String> cm = getPicklistValues('Contract__c','Corpcode__c');
		///产品对应的公司
		Map<Id,String>  comMap= new Map<Id,String>();
		for (Price__c p :plist) {

			if (!comMap.containsKey(p.Product__c)) {
				comMap.put(p.Product__c, cm.get(p.Company__c));
			}else{
				String com = comMap.get(p.Product__c);
				if(com.contains(p.Company__c))continue;
				com += +','+ cm.get(p.Company__c);
				comMap.put(p.Product__c, com);
			}
		}
		List<Product__c> proList = new List<Product__c>();

		for (Product__c p :[select Id from Product__c where Id in:proset] ) {
			if (comMap.containsKey(p.Id)) {
				p.PriceCompany__c = comMap.get(p.id);
				
			}else{
				p.PriceCompany__c = null;

			}
			proList.add(p);
		}
		if (proList.size() > 0) update proList; 
	}

	///删除 或 新增
	public static void deleteCom (List<Price__c> plist){
		Set<Id> proset = new Set<Id>();
		for (Price__c p : plist) {
			proset.add(p.Product__c);
		}
		if( proset.size() > 0)gatherCom(proset);
		
	}
	///更新
	public static void updateCom (List<Price__c> plist,Map<Id,Price__c> oldMap){
		Set<Id> proset = new Set<Id>();

		for (Price__c p : plist) {
			 Price__c oldp  = oldMap.get(p.Id);
			 if(oldp.Product__c != p.Product__c)proset.add(oldp.Product__c);
			 	 proset.add(p.Product__c);
		}
		if( proset.size() > 0)gatherCom(proset);		
	}

	 //获得PickList的值
    public static Map<String, String> getPicklistValues(String sObjectName, String sFieldName){
        Map<String, String> picValues= new Map<String, String>();
        Map<String, Schema.SObjectType> sObjectDescribeMap = Schema.getGlobalDescribe();
        if (sObjectDescribeMap.containsKey(sObjectName)) {
            Map<String, Schema.SobjectField> sObjectFieldsMap = 
               sObjectDescribeMap.get(sObjectName).getDescribe().fields.getMap();
            if (sObjectFieldsMap.containsKey(sFieldName)) {
                Schema.DescribeFieldResult sObjectFieldDescribe = sObjectFieldsMap.get(sFieldName).getDescribe();
                List<Schema.PicklistEntry> lPickEntryList = sObjectFieldDescribe.getPicklistValues();
                for (Schema.PicklistEntry tPicklistEntry : lPickEntryList) {
                    if(tPicklistEntry.isActive() == true){
                        picValues.put(tPicklistEntry.getLabel(),tPicklistEntry.getValue());
                    }
                    /*picValues.put(tPicklistEntry.getValue(), new Map<String,object>{
                        'value' => tPicklistEntry.getValue(),
                        'isActive' => tPicklistEntry.isActive(),
                        'isDefaultValue' => tPicklistEntry.isDefaultValue(),
                        'label' => tPicklistEntry.getLabel()
                    });*/
                }
            } else {
                //TODO 不存在此字段的执行
            }
        } else {
            // TODO 不存在此sObject的执行
        }
        return picValues;
    }


}